package com.ruoyi.worker.domain;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;


/**
 * 拉黑员工名单对象 rz_block_worker
 *
 * @author Hush
 * @since 2021-12-15
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Accessors(chain = true)
public class RzBlockWorker extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * id主键
     */
    private Long id;

    /**
     * 员工id 依据员工类型判断
     * @see RzBlockWorker#workerType
     */
    @NotNull(message = "员工id不可为空")
    private Long workerId;

    /**
     * 员工姓名
     */
    @Excel(name = "员工姓名")
    @NotBlank(message = "员工姓名不可为空")
    private String workerName;

    /**
     * 员工性别 1 男 2 女
     */
    @Excel(name = "员工性别",readConverterExp = "1=男,2=女")
    private Integer sex;

    /**
     * 员工身份证号码
     */
    @Excel(name = "员工身份证号码")
    @NotBlank(message = "员工身份证号码不可为空")
    private String idCard;

    /**
     * 员工年龄
     */
    @Excel(name = "员工年龄")
    private Long age;

    /**
     * 员工手机号码
     */
    @Excel(name = "员工手机号码")
    private String phoneCode;

    /**
     * 员工类型 1:长期工 2:临时工
     */
    @Excel(name = "员工类型 1:长期工 2:临时工",readConverterExp = "1=长期工,2=临时工")
    private Integer workerType;

    /**
     * 拉黑备注
     */
    @Excel(name = "拉黑备注")
    @NotNull(message = "拉黑原因不可为空")
    private String blockRemark;


    public void setIdCard(String idCard) {
        this.idCard = idCard;
        if (StringUtils.isNotEmpty(idCard)){
            Map<String, String> map = DateUtils.getBirthdayAgeSex(idCard);
            sex = Convert.toInt(map.get("sex"));
            age = Convert.toLong(map.get("age"));
        }
    }
}
